﻿using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace ESoft.DataAccess.EfCore.SqlServer
{
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// 启动
        /// </summary>
        /// <param name="service"></param>
        /// <param name="connectStr"></param>
        /// <param name="assemblies"></param>
        public static void AddEfCoreMySql(this IServiceCollection service, string connectStr,
            params Assembly[] assemblies)
        {
            DatabaseInitializer.AddMapperAssembly(assemblies);
            service.AddDbContext<DataContext>(options => options.UseSqlServer(connectStr));
            service.AddTransient<IBaseReponsitory, BaseRepositry>();

            service.AddTransient<ISqlRepositry, SqlServerQueryRepositry>();
        }
    }
}